<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="container-div">
    	<div class="row">
	        <!-- <div class="btn-group hidden-xs" id="toolbar" role="group">
		        <button class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add()" shiro:hasPermission="module:leave:add">
		            <i class="fa fa-plus"></i> 新增
		        </button>
		        <button class="btn btn-outline btn-danger btn-rounded" onclick="$.operate.batRemove()" shiro:hasPermission="module:leave:remove">
		            <i class="fa fa-trash-o"></i> 删除
		        </button>
	        </div> -->
	        <div class="col-sm-12 select-info order-table">
		        <table id="bootstrap-table" data-mobile-responsive="true">
		        </table>
	        </div>
	    </div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var prefix = ctx + "module/leave"

        $(function() {
            var options = {
                url: prefix + "/list",
                modalName: "请假",
                search: false,
		        showExport: false,
                columns: [{
		            checkbox: true
		        },
		        {
		            title: '序号',
		            field: '',
		            align: 'center',
		            formatter: function (value, row, index) {
		                var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
		                var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
		                return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
		            }
		        },
				{
					field : 'title', 
					title : '标题' 
				},
				{
					field : 'parent.name', 
					title : '申请人' 
				},
				{
					field : 'content', 
					title : '内容' 
				},
				{
					field : 'startTime', 
					title : '开始时间' 
				},
				{
					field : 'endTime', 
					title : '结束时间' 
				},
				{
					field : 'status', 
					title : '状态',
					formatter: function(value, row, index) {
						if (value == '0') {
		                    return '<span class="badge badge-danger">未审批</span>';
		                } else if(value == '1') {
		                    return '<span class="badge badge-primary">已审批</span>';
		                }else{
		                    return '<span class="badge badge-primary">驳回</span>';
		                }
		            }
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	if(row.status == '0'){
	                        actions.push('<a class="btn btn-success btn-xs " href="#" onclick="updateStatus(\''+row.leaveId+'\',\'1\')"><i class="fa fa-edit"></i> 同意 </a>');
	                        actions.push('<a class="btn btn-danger btn-xs " href="#" onclick="updateStatus(\''+row.leaveId+'\',\'2\')"><i class="fa fa-remove"></i> 驳回 </a>');
		            	}
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        
        function updateStatus(leaveId,status){
        	var m = status=="1"?"同意":"驳回";
        	$.modal.confirm("确定要"+m+"该申请吗？",function(){
        		var data = {
                    "leaveId": leaveId,
                    "status": status
                };
                $.operate.submit(prefix+"/updateStatus", "post", "json", data);
        	});
        }
    </script>
</body>
</html>